﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Collections;

namespace CDTM.Modules.TraCuuDiem.Components
{
    public partial class Lop
    {

        //---------------------------------------------------------------------------------------------

        public static DataSet SelectAllLop()
        {
            const string spName = "[dbo].[p_CDTM_Lop_SelectGroup]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            return db.ExecuteDataSet(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static DataSet SelectQuyenByLop(string lop)
        {
            return SelectGroupDynamic("Lop ='" + lop + "'", "");
        }

        //---------------------------------------------------------------------------------------------

        public static DataSet SelectQuyenAllLop()
        {
            return SelectGroupDynamic("1=1", "");
        }

        //---------------------------------------------------------------------------------------------

        private static DataSet SelectGroupDynamic(string whereCondition, string orderByExpression)
        {
            const string spName = "[dbo].[p_CDTM_Lop_SelectGroupDynamic]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}
